<template>
  <div class="xtx-pay-page">
    <div class="container">
       <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item to="/cart">购物车</el-breadcrumb-item>
        <el-breadcrumb-item>支付订单</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 付款信息 -->
      <div class="pay-info">
        <span class="icon iconfont icon-queren2"></span>
        <div class="tip">
          <p>订单提交成功！请尽快完成支付。</p>
          <p>支付还剩 <span>{{timeText}}</span>, 超时后将取消订单</p>
        </div>
        <div class="amount">
          <span>应付总额：</span>
          <span v-if="order">￥{{order.totalMoney}}</span>
        </div>
      </div>
      <!-- 付款方式 -->
      <div class="pay-type">
        <p class="head">选择以下支付方式付款</p>
        <div class="item">
          <p>支付平台</p>
          <a class="btn wx" href="javascript:;" @click="wxDialogVisible = true"></a>
          <a class="btn alipay" :href="payUrl" target="_blank" @click="dialogVisible=true" ></a>
        </div>
        <el-dialog
          title="支付"
          v-model="wxDialogVisible"
          width="500px">
          <div class="wxImg">
            <img src="@/assets/images/二维码.png" alt="">
          </div>
        </el-dialog>
        <div class="item">
          <p>支付方式</p>
          <a class="btn" href="javascript:;">招商银行</a>
          <a class="btn" href="javascript:;">工商银行</a>
          <a class="btn" href="javascript:;">建设银行</a>
          <a class="btn" href="javascript:;">农业银行</a>
          <a class="btn" href="javascript:;">交通银行</a>
        </div>
        <!-- 支付框 -->
        <el-dialog title="正在支付" v-model="dialogVisible" width="50%">
          <div class="payDialog">
            <img src="@/assets/images/load.gif" alt="">
            <div>
              <div class="item">
                <p>如果支付成功：</p>
                <p @click="$router.push('/member/order/'+$route.query.id) ">查看订单详情></p>
              </div>
              <div class="item">
                <p>如果支付失败：</p>
                <p>查看订单疑问></p>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
// 买家账号jfjbwb4477@sandbox.com
// 登录密码111111
// 支付密码111111
import { ref } from 'vue'
import { findOrder } from '@/api/order'
import { useRoute } from 'vue-router'
import { usePayTime } from '@/hooks'
import { baseURL } from '@/utils/request'
export default {
  name: 'XtxPayPage',
  setup(){
    const wxDialogVisible = ref(false)
    // 订单
    const order = ref(null)
    // 路由信息
    const route = useRoute()
      // 查询订单
    findOrder(route.query.id).then(data => {
      // 设置订单
      order.value = data.result
      if(data.result.countdown > -1){
        start(data.result.countdown)
      }
    })
    const { start, timeText} = usePayTime()
    // 回调地址
    const redirect = encodeURIComponent('http://localhost:8080/#/pay/callback')
    // 支付地址
    const payUrl = ` ${baseURL}/pay/aliPay?orderId=${route.query.id}&redirect=${redirect}`
    const dialogVisible = ref(false)
    return {
      wxDialogVisible,
      order,
      timeText,
      payUrl,
      dialogVisible
    }
  }
}
</script>
<style scoped lang="scss">
.payDialog{
  display: flex;
  justify-content: space-around;
  align-items: center;
  img{
    width: 300px;
    height: 300px;
  }
  .item{
    margin-top: 20px;
    p{
      height: 30px;
      line-height: 30px;
    }
    & p:last-child{
      color: $xtxColor;
    }
  }
}
.el-breadcrumb {
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 70px;
  }
  .wxImg{
    width: 300px;
    margin: auto;
  }
.pay-info {
  background: #fff;
  display: flex;
  align-items: center;
  height: 240px;
  padding: 0 80px;
  .icon {
    font-size: 80px;
    color: #1dc779;
  }
  .tip {
    padding-left: 10px;
    flex: 1;
    p {
      &:first-child {
        font-size: 20px;
        margin-bottom: 5px;
      }
      &:last-child {
        color: #999;
        font-size: 16px;
      }
    }
  }
  .amount {
    span {
      &:first-child {
        font-size: 16px;
        color: #999;
      }
      &:last-child {
        color: $priceColor;
        font-size: 20px;
      }
    }
  }
}
.pay-type {
  margin-top: 20px;
  background-color: #fff;
  padding-bottom: 70px;
  p {
    line-height: 70px;
    height: 70px;
    padding-left: 30px;
    font-size: 16px;
    &.head {
      border-bottom: 1px solid #f5f5f5;
    }
  }
  .btn {
    width: 150px;
    height: 50px;
    border: 1px solid #e4e4e4;
    text-align: center;
    line-height: 48px;
    margin-left: 30px;
    color: #666666;
    display: inline-block;
    &.active,
    &:hover {
      border-color: $xtxColor;
    }
    &.alipay {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7b6b02396368c9314528c0bbd85a2e06.png) no-repeat center / contain;
    }
    &.wx {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c66f98cff8649bd5ba722c2e8067c6ca.jpg) no-repeat center / contain;
    }
  }
}
</style>